import React, {Component} from 'react';
import Taro from '@tarojs/taro';
import {View} from '@tarojs/components'
import {user} from '../../../utils/user.service'
import {h5Wx} from "../../../utils/h5.service";
import {http} from "../../../utils/http";
import {GET_TOTAL_INTEGRAL} from "../../../constants/api";
import {vcmonitor} from "../../../utils/tools";
import GzhAuth from "../../../components/gzh-auth/gzh-auth"
import './integral.scss'

export default class Integral extends Component {
  state: {
    records: any
  } = {
    records: []
  }

  async UNSAFE_componentWillMount() {
    if (process.env.TARO_ENV === 'h5') {
      await h5Wx.getConfig()
    }
    const isLogin = await user.checkLogin()
    if (!isLogin) {
      Taro.showToast({
        title: '你还未登录，请登录',
        icon: 'none',
      })
      const timer = setTimeout(() => {
        clearTimeout(timer)
        Taro.switchTab({url: '/pages/my/index/index'})
      }, 1500)
      return
    }
    await this.getData()
  }

  async componentDidShow() {
    vcmonitor(this)
  }

  page = 1

  async getData() {
    const totalIntegral = await http.get(GET_TOTAL_INTEGRAL, {})
    this.setState({records: totalIntegral.bn_integral_configs_list})
  }

  render() {
    const {records} = this.state
    return (
      <View className='my-integral-root'>
        <GzhAuth />
        <View className='rules'>
          <View className='left-line' />
          {records && records.length > 0 && records.map((item, index) =>
            <View className='rules-content' key={index}>
              <View className='round' />
              <View className='rules-str'>{item.integral_roles_str}</View>
            </View>)}
        </View>
      </View>
    )
  }
}
